<template>
  <div>
    <el-table height=window.screen.height stripe border style="width:100%" highlight-current-row :data="tableData" v-loading="loading">

      　　

      　　<el-table-column prop="id" label="订单ID" align="center" min-width="60" fixed="left">
      </el-table-column>
      <el-table-column prop="useruid" label="用户ID" align="center" min-width="60">
      </el-table-column>
      <el-table-column prop="maijiauid" label="卖家ID" align="center" min-width="60">
      </el-table-column>
      <el-table-column prop="productId" label="商品ID" align="center" min-width="60">
        　　
      </el-table-column>
      　　 <el-table-column prop="days" label="租赁时长" align="center" min-width="60">
      </el-table-column>
      <el-table-column prop="totalPrice" label="租金" align="center" min-width="60">
      </el-table-column>



      　　 <el-table-column prop="fahuoaddress" label="发货地址" align="center" min-width="120" show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column prop="jihuiaddress" label="收货地址" align="center" min-width="120" show-overflow-tooltip="true">
      </el-table-column>


      　　 <el-table-column prop="jiwuliu" label="发出物流" align="center" min-width="80">
      </el-table-column>
      <el-table-column prop="fawuliu" label="回寄物流" align="center" min-width="80">
      </el-table-column>


      　　
      <el-table-column prop="status" label="发货状态" align="center" min-width="80">
        <template slot-scope="scope">
          {{ scope.row.status == '4' ? "卖家提货" :scope.row.status == '5' ? "订单完成" :scope.row.status == '3' ? "买家寄回" : scope.row.status == '2' ? "买家提货" : scope.row.status
              == '1' ? "商家发货" : scope.row.status == '0' ? "买家下单" : ''
          }}
        </template>
      </el-table-column>


      　　
      <el-table-column label="操作" align="center" width="100" fixed="right">
        　　　　
        <template slot-scope="scope">
          　　　　　　
          <el-button size="small" type="info" @click="deleteOrder(scope.row.id)">完成订单</el-button>
        </template>
        　　
      </el-table-column>
    </el-table>
  </div>

</template>

<script>
export default {
  data() {
    return {
      tableData: [{
        id: '',
        useruid: '',
        maijiauid: '',
        productId: '',
        days: '',
        totalPrice: '',
        fahuoaddress: '',
        jihuiaddress: '',
        jiwuliu: '',
        fawuliu: '',
        status: '',

        edit: false
      },
      ],
      loading:false

    }
  },
  methods: {
    init() {
      {
        if (localStorage.orders) {
          this.tableData = JSON.parse(localStorage.orders)
        } else {
          this.axios({
            method: 'GET',
            url: "https://admin.xiaoheihe.work/bapi/getallorders"
          }).then(response => {
            console.log(response.data);
            this.tableData = response.data
            localStorage.orders = JSON.stringify(response.data);
            setTimeout(() => {
              removeLocalStorage(orders);
            }, 300000)
          })

        }

      }
    },

    deleteOrder(id) {
      console.log(id)
      this.axios({
        method: "patch",
        url: "https://admin.xiaoheihe.work/bapi/deleteorder",
        data: {
          id: id,
        }
      }).then(res => {
        console.log(res.data)

        if (res.data == 'OK') {
          let getorders = localStorage.getItem("orders");
          localStorage.removeItem(getorders);

          this.axios({
            method: 'GET',
            url: "https://admin.xiaoheihe.work/bapi/getallorders"
          }).then(response => {
            console.log(response.data);
            this.tableData = response.data
            localStorage.orders = JSON.stringify(response.data);
          })
          this.init()
        }


      })
    },
  },
  created() {
    this.init();
  }
}
</script>
